// index.js
// 获取应用实例
const app = getApp()
//const seturl = require('../../utils/request');

Page({
  data:{
    name:"",
    password:"",
    message:"",
    isRemember: false,

    warnToast: false,
    hideWarnToast: false
  },

  nameInput(e){
    this.setData({
      name: e.detail.value
    })
  },

  pawInput(e){
    this.setData({
      password: e.detail.value
    })
  },

  formSubmit(e) {
    console.log('form发生了submit事件，携带数据为：', this.data)
    let{name, password} = this.data;
    let postData = {
      name: this.data.name,
      password: this.data.password
    }
    postData = {...this.data}
    postData = {name,password}

    wx.request({
      url: 'http://localhost/public/index/login/Login',
      method: "POST",
      data: postData,
      success: ({data}) => {
        console.log(data);
        console.log(data.status);
        if(data.status === 'success'){
          console.log(data);
          app.globalData.userstatus = data.userstatus;
          app.globalData.userId = data.Id;
          app.globalData.userName = data.userName;
          wx.switchTab({
            url: '/pages/course/course',
          })
        }else{
          this.setData({
            warnToast: true,
            message:data.message
          });
          setTimeout(() => {
            this.setData({
                hidewarnToast: true,
            });
            setTimeout(() => {
              this.setData({
                  warnToast: false,
                  hidewarnToast: false,
              });
            }, 300);
          }, 3000);
          console.log(data.message);
        }
      },
      fail:(err)=> {
        console.log(err);
      }
    })
    
  },

  formReset(e) {
    console.log('form发生了reset事件，携带数据为：', e.detail.value)
    this.setData({
      chosen: ''
    })
  }
})
